home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvichk / dvichk.c < prev    next >
C/C++ Source or Header  |  1993-02-25  |  31KB  |  917 lines

  1. /*
  2.    ************************************************************************
  3.    *                                                                      *
  4.    *  Thomas Esken Software, Im Hagenfeld 84, W-4400 M"unster , GERMANY   *
  5.    *  ------------------------------------------------------------------  *
  6.    *                                                                      *
  7.    *  It is not allowed to pass on or commercialize this program, to      *
  8.    *  inform about the contents or part of the contents and to duplicate  *
  9.    *  it in any form, as far as not expressly authorized by a written     *
  10.    *  permit !!                                                           *
  11.    *  This software doesn't claim completeness, correctitude or           *
  12.    *  usability. On principle I will not be liable for any damages or     *
  13.    *  losses, which result from using or handling my software. If you     *
  14.    *  use this software, you agree without any exception to this          *
  15.    *  agreement, which binds you legally !!                               *
  16.    *                                                                      *
  17.    *  DVIChk  .C   - Checks the page numbers of a TeX -> .dvi/.log-file.  *
  18.    *  Sketch  :    - 1990/11/05 - TOM , 4400 MS, BRD, Tel.:0251 / 232585  *
  19.    *  Version :    - 1.60-BETA  - (C)opyright 1990-93  -   Update:930226  *
  20.    *                                                                      *
  21.    ************************************************************************
  22.  
  23.  
  24.  
  25.  
  26.    Primary output from p2c, the Pascal-to-C translator !
  27.    Further modification by :
  28.  
  29.      <esken@obelix.uni-muenster.de>
  30.      <find03@fx1.hrz.uni-dortmund.de>
  31.  
  32.   
  33.   
  34.    !!!  This is a BETA testing release  !!!
  35.   
  36.   
  37.  
  38.    System requirements :
  39.    ---------------------
  40.      Compiler         : any? ANSI-C compiler (GCC...)
  41.      Computer         : Un*x Workstation (resp., Mainfraime)
  42.      RAM              : about 100 KByte load size
  43.      Graphics adapter : none
  44.      Harddisk         : none
  45.  
  46.  
  47.    Agreement of use :
  48.    ------------------
  49.    Differing from the conditions of use, which are referenced in the program
  50.    header, private users or public scientific institutions are allowed to
  51.    modify this program according to their requirements resp. to adapt this
  52.    program to their target computer. For that purpose it is allowed to
  53.    translate the algorithm, which is used in this program, to an other
  54.    programing language. The modified program may be distributed only
  55.    FREE OF CHARGE as freeware or public domain software ; moreover a short
  56.    reference to me, the author of DVIChk, must be implemented in the program
  57.    documentation. In spite of the relaxation of the conditions of use, the
  58.    non guarantee clause resp. clause of exclusion of liability are valid.
  59.  
  60.    Please send bug reports, extensions or improvements of this program
  61.    to me, the author !!
  62.  
  63.  
  64.    Short program description :
  65.    ---------------------------
  66.    According to the delivered command line options, a single .dvi- resp.
  67.    .log-file, which is created by the TeX-formatter, is checked. The page
  68.    numbers, which are found in the formatted text or it's .log-file, are
  69.    shown on the standard output device in a formatted manner.
  70.  
  71.    Any wildcard characters are NOT allowed in a file name !!
  72.  
  73.  
  74.    The format of a .dvi-file of the TeX-formatter is as follows? :
  75.    ---------------------------------------------------------------
  76.    first   block  of data = preamble (any? sequence of bytes + date of
  77.                             formatting), then 0x8b,
  78.                             after this the 64bit page number xxxx,
  79.                             which must be read from right to left !
  80.    further blocks of data = 0x8c0x8b, then the 64bit page number xxxx,
  81.                             which must be read from right to left !
  82.    last    block  of data = 0x8c0xf8, then information about the used fonts.
  83.  
  84.  
  85.    The format of a .log-file of the TeX-formatter is as follows :
  86.    --------------------------------------------------------------
  87.    All page numbers are marked/introduced by the open bracket (== [ ). The
  88.    following character(s) must be numeral(s), e.g., [13]. The only exception
  89.    is a nested or negative page number like [13.1], so the dot and the
  90.    minus sign (roman numeral) must be respected too.
  91.  
  92.  
  93.    Internal set return-codes  :
  94.    ----------------------------
  95.      unknown command line option =  255
  96.      no file name present        =  254
  97.      ask for help                =  253
  98.      invalid or corrupted file   =  252
  99.  
  100.  
  101.    Default program output is in English.
  102.    Write `#define GERMAN' below this comment 
  103.      OR !! in your Makefile (-DGERMAN) for using German program output !
  104. */
  105.  
  106.  
  107. #include "p2c.h"
  108.  
  109.  
  110. #define  PRGR_NAME       "DVIChk"
  111. #define  VERSION_NO      "v1.60-BETA"
  112. #define  pages_max       2499
  113. #define  blocksize       32767
  114. #define  suffix_dvi      ".dvi"
  115. #define  suffix_log      ".log"
  116. #define  id_byte_one     0x8b
  117. #define  id_byte_two     0x8c
  118. #define  id_char_one     '['
  119. #define  id_char_two     ']'
  120. #define  columns_max     8
  121. #define  column_width    10
  122. #define  copyright       PRGR_NAME" "VERSION_NO"  (c)1990-93 Thomas Esken, " \
  123.                          "Im Hagenfeld 84, W-4400 M\"unster\n"
  124. #define  underline       "-------------------------------------------------" \
  125.                          "---------------------------\n"
  126. #define  MY_ARGC_MAX     255
  127. #define  STR_LEN_MAX     81
  128.  
  129.  
  130. typedef Char string_sizeof_pathstr[STR_LEN_MAX];
  131. typedef Char stringX[column_width+1];
  132. typedef
  133.   enum
  134.     {
  135.       check_dvi, check_log
  136.     }
  137.   checkmode_type;
  138.  
  139.  
  140. Static uchar                   column_quantity                  = 4;
  141. Static boolean                 with_message                     = true;
  142. Static FILE                   *f;
  143. Static FILE                   *t;
  144. Static uchar                   dvibuf[blocksize+1];
  145. extern Char                   *textbuf                          = dvibuf;
  146. Static stringX                 document_pages[pages_max+1];
  147. Static string_sizeof_pathstr   s,
  148.                                fn;
  149. Static checkmode_type          mode;
  150. Static Char                    textline[256];
  151. Static unsigned short          parameter_quantity,
  152.                                pages,
  153.                                error,
  154.                                x,
  155.                                i,
  156.                                j;
  157. Static boolean                 textline_finished,
  158.                                buffer_finished,
  159.                                first_buffer,
  160.                                read_textline,
  161.                                delete_next_bracket,
  162.                                id_byte_one_found,
  163.                                id_byte_two_found;
  164. Static Char                    f_NAME[_FNSIZE];
  165. Static Char                    t_NAME[_FNSIZE];
  166.  
  167.  
  168.  
  169.  
  170.  Static Char *pagenumber_decimal (Char *Result,
  171.                                   uchar a,uchar b,uchar c,uchar d)
  172.  /*
  173.     Converts the four delivered bytes, which embody a 64bit value (Hi .. Lo),
  174.     to a decimal number.
  175.  */
  176.  {
  177.    long     x;
  178.    stringX  s;
  179.  
  180.  
  181.    x =   (a >> 4) * 0x10000000L
  182.        + (a & 15) * 0x1000000L
  183.        + (b >> 4) * 0x100000L
  184.        + (b & 15) * 0x10000L
  185.        + (c >> 4) * 0x1000
  186.        + (c & 15) * 0x100
  187.        + d;
  188.    sprintf(s,"%ld",x);
  189.  
  190.    return(strcpy(Result,s));
  191.  }
  192.  
  193.  
  194.  Static boolean pagenumber_ok (Char *s)
  195.  /*
  196.     Check whether the page number, which is found, is valid and no thing
  197.     like [20pt] ... etc. (log_check) !!
  198.  */
  199.   {
  200.     boolean  Result;
  201.     uchar    i,j;
  202.  
  203.  
  204.     Result = true;
  205.     i = strlen(s);
  206.     j = 1;
  207.     while (j < i)
  208.      {
  209.        if (   (   j == 1
  210.                && (   s[j - 1] == '-'
  211.                    || isdigit(s[j - 1])))
  212.            || (   j > 1
  213.                && (   s[j - 1] == '.'
  214.                    || isdigit(s[j - 1]))))
  215.          j++;
  216.        else
  217.         {
  218.           Result = false;
  219.           j = i;
  220.         }
  221.      }
  222.  
  223.     return(Result);
  224.   }
  225.  
  226.  
  227.  Static void error_stop (unsigned short error)
  228.  /*
  229.     If an error occurs, print a corresponding message,
  230.     set the return code and terminate the program.
  231.  */
  232.   {
  233.     if (error == 253)
  234.      {
  235. #ifdef GERMAN
  236.        printf("+---------------------------------------------------------+\n");
  237.        printf("|  "PRGR_NAME"-Hilfeseite von Thomas Esken Software  (c)90-93  |\n");
  238.        printf("+---------------------------------------------------------+\n");
  239.        printf("|                                                         |\n");
  240.        printf("|  "PRGR_NAME" "VERSION_NO"  pr\"uft eine von TeX erstellte       |\n");
  241.        printf("|  .dvi/.log-Datei auf den Seitenumfang des formatierten  |\n");
  242.        printf("|  Textes ab und gibt die Seitenzahlen auf der Standard-  |\n");
  243.        printf("|  ausgabe aus. Diese Ausgabe kann in einer Textdatei     |\n");
  244.        printf("|  mittels der Umleitungoperators  >  gesichert werden !  |\n");
  245.        printf("|                                                         |\n");
  246.        printf("|  Aufruf:  "PRGR_NAME" [argumente...] <dateiname>             |\n");
  247.        printf("|                                                         |\n");
  248.        printf("+---------------------------------------------------------+\n");
  249.        printf("|  -> dateiname == .dvi/.log-Datei OHNE Wildcards (*?)    |\n");
  250.        printf("+---------------------------------------------------------+\n");
  251.        printf("|  -> argumente == -? (+?)     == zeigt diesen Text       |\n");
  252.        printf("|                  -[dvi][log] == Pr\"ufen der .dvi-Datei  |\n");
  253.        printf("|                                 bzw.    der .log-Datei  |\n");
  254.        printf("|                  -s[1..8]    == 1..8-spaltige Ausgabe   |\n");
  255.        printf("|                  -m[+][-]    == Ausgabe mit / ohne      |\n");
  256.        printf("|                                 weiteren Informationen  |\n");
  257.        printf("+---------------------------------------------------------+\n");
  258. #else
  259.        printf("+--------------------------------------------------------+\n");
  260.        printf("|  "PRGR_NAME"-help page  by  Thomas Esken Software (c)90-93  |\n");
  261.        printf("+--------------------------------------------------------+\n");
  262.        printf("|                                                        |\n");
  263.        printf("|  "PRGR_NAME" "VERSION_NO"  checks the page numbers of a       |\n");
  264.        printf("|  formatted text in a .dvi/.log-file which is created   |\n");
  265.        printf("|  by the TeX-formatter, and outputs the page numbers on |\n");
  266.        printf("|  standard output. This output can be stored in a text  |\n");
  267.        printf("|  file via the I/O-redirection operator   >   !!        |\n");
  268.        printf("|                                                        |\n");
  269.        printf("|  Usage:  "PRGR_NAME" [options...] <file name>               |\n");
  270.        printf("|                                                        |\n");
  271.        printf("+--------------------------------------------------------+\n");
  272.        printf("|  -> file name == .dvi/.log-file WITHOUT wildcards (*?) |\n");
  273.        printf("+--------------------------------------------------------+\n");
  274.        printf("|  -> options   == -? (+?)     == shows this text        |\n");
  275.        printf("|                  -[dvi][log] == checks a .dvi-file     |\n");
  276.        printf("|                                 resp., a .log-file     |\n");
  277.        printf("|                  -s[1..8]    == 1..8 column numbers    |\n");
  278.        printf("|                  -m[+][-]    == output further /       |\n");
  279.        printf("|                                 no other informations  |\n");
  280.        printf("+--------------------------------------------------------+\n");
  281. #endif
  282.      }
  283.     else
  284.      {
  285.        if (with_message)
  286.         {
  287.           fputs(copyright,stderr);
  288.           fputs(underline,stderr);
  289. #ifdef GERMAN
  290.           fprintf(stderr,"FEHLER (%u) :  ",error);
  291. #else
  292.           fprintf(stderr,"ERROR (%u) :  ",error);
  293. #endif
  294.           switch (error)
  295.            {
  296.              case 255:
  297. #ifdef GERMAN
  298.                fprintf(stderr,"Unbekannte Aufrufoption :  %s",s);
  299. #else
  300.                fprintf(stderr,"Unknown option :  %s",s);
  301. #endif
  302.                break;
  303.              case 254:
  304. #ifdef GERMAN
  305.                fprintf(stderr,"Kein Dateiname angegeben");
  306. #else
  307.                fprintf(stderr,"No file name present");
  308. #endif
  309.                break;
  310.              case 252:
  311. #ifdef GERMAN
  312.                fprintf(stderr,"%s ist keine ",fn);
  313. #else
  314.                fprintf(stderr,"%s is no ",fn);
  315. #endif
  316.                if (mode == check_dvi)
  317.                  fputs(suffix_dvi,stderr);
  318.                else
  319.                  fputs(suffix_log,stderr);
  320. #ifdef GERMAN
  321.                fprintf(stderr,"-Datei oder defekt");
  322. #else
  323.                fprintf(stderr,"-file or corrupted");
  324. #endif
  325.                break;
  326.              default:
  327. #ifdef GERMAN
  328.                fprintf(stderr,"Beim Verarbeiten der ");
  329. #else
  330.                fprintf(stderr,"Processing ");
  331. #endif
  332.                if (mode == check_dvi)
  333.                  fputs(suffix_dvi,stderr);
  334.                else
  335.                  fputs(suffix_log,stderr);
  336. #ifdef GERMAN
  337.                fprintf(stderr,"-Datei %s",fn);
  338. #else
  339.                fprintf(stderr,"-file %s",fn);
  340. #endif
  341.                break;
  342.            }
  343.           fprintf(stderr,"  !!\n");
  344. #ifdef GERMAN
  345.           fprintf(stderr,PRGR_NAME" -? (+?)  f\"ur Hilfestellung\n");
  346. #else
  347.           fprintf(stderr,PRGR_NAME" -? (+?)  for help\n");
  348. #endif
  349.         }
  350.        exit((signed int)error);
  351.      }
  352.   }
  353.  
  354.  
  355.  
  356.  
  357. int main(int argc, Char **argv)
  358. /*
  359.    main program DVIChk
  360. */
  361.  {
  362.    unsigned short   FORLIM,FORLIM1;
  363.    Char             STR1[256],
  364.                     STR2[256],
  365.                     STR3[256],
  366.                     STR4[256];
  367.    Char             STR5[4];
  368.    Char            *TEMP;
  369.    Char            *my_argv[MY_ARGC_MAX+1];
  370.    int              my_argc;
  371.    Char            *ptr_my_argv;
  372.  
  373.  
  374.    setbuf(stdout,0);
  375.    PASCAL_MAIN(argc,argv);
  376.    t = NULL;
  377.    f = NULL;
  378.    for (my_argc=0 ;
  379.         P_argv[my_argc] != NULL && my_argc < MY_ARGC_MAX;
  380.         my_argc++)
  381.     {
  382.       ptr_my_argv = malloc((unsigned)strlen(P_argv[my_argc])+1);
  383.       if (ptr_my_argv != NULL)
  384.        {
  385.          strcpy(ptr_my_argv,P_argv[my_argc]);
  386.          my_argv[my_argc] = ptr_my_argv;
  387.        }
  388.     }
  389.    my_argv[my_argc] = NULL;
  390.    my_argc = (my_argc >= MY_ARGC_MAX ?  MY_ARGC_MAX : P_argc);
  391. LABEL_start:
  392.    mode = check_dvi;
  393.    error = 0;
  394.    *fn = '\0';
  395.    if (my_argc == 1)
  396.      parameter_quantity = 1;
  397.    else
  398.      parameter_quantity = my_argc - 1;
  399.    FORLIM = parameter_quantity;
  400.    for (i=1 ; i <= FORLIM ; i++)
  401.     {
  402.       if (my_argc == 1)
  403.         strcpy(s,"?");
  404.       else
  405.         {
  406.           x = strlen(my_argv[i]);
  407.           strncpy(s,my_argv[i],STR_LEN_MAX);
  408.           if (x >= STR_LEN_MAX)
  409.             s[STR_LEN_MAX] = '\0';
  410.         }
  411.       if (   s[0] == '?'
  412.           || (   s[0] == '-'
  413.               && s[1] == '?')
  414.           || (   s[0] == '+'
  415.               && s[1] == '?'))
  416.        {
  417.          error_stop (253);
  418.          if (s[0] != '?')
  419.            exit(253);
  420.          else
  421.           {
  422.             signed char            ch;
  423.             signed int             i,j,k;
  424.             string_sizeof_pathstr  str;
  425.  
  426.  
  427. #ifdef GERMAN
  428.             printf("Eingabe [argumente] <dateiname>...");
  429. #else
  430.             printf("Enter [options] <file name>...");
  431. #endif
  432.             i = 0;
  433.             while (   (ch = fgetc(stdin)) != EOF
  434.                    && ch != '\n'
  435.                    && i < STR_LEN_MAX - 1)
  436.               s[i++] = ch;
  437.             s[i] = '\0';
  438.             if (!s[0])
  439.               exit(0);
  440.             else
  441.              {
  442.                i = strlen(s) - 1;
  443.                while (   isspace(s[i])
  444.                       && i >= 0)
  445.                  s[i--] = '\0';
  446.                i=k = 0;
  447.                j = 1;
  448.                ptr_my_argv = my_argv[j];
  449.                while (   s[i]
  450.                       && j < MY_ARGC_MAX)
  451.                 {
  452.                   if (!isspace(s[i]))
  453.                     str[k++] = s[i];
  454.                   else
  455.                    {
  456.                      str[k] = '\0';
  457.                      ptr_my_argv = realloc(ptr_my_argv,strlen(str)+1);
  458.                      if (ptr_my_argv != NULL)
  459.                       {
  460.                         strcpy(ptr_my_argv,str);
  461.                         my_argv[j] = ptr_my_argv;
  462.                       }
  463.                      k = 0;
  464.                      j++;
  465.                      ptr_my_argv = my_argv[j];
  466.                    }
  467.                   i++;
  468.                 }
  469.                if (j != MY_ARGC_MAX)
  470.                 {
  471.                   str[k] = '\0';
  472.                   ptr_my_argv = realloc(ptr_my_argv,strlen(str)+1);
  473.                   if (ptr_my_argv != NULL)
  474.                    {
  475.                      strcpy(ptr_my_argv,str);
  476.                      my_argv[j] = ptr_my_argv;
  477.                    }
  478.                   if (s[0])
  479.                     my_argc = ++j;
  480.                 }
  481.                else
  482.                  if (s[0])
  483.                    my_argc = j;
  484.                my_argv[j] = (Char *)NULL;
  485.                goto LABEL_start;
  486.              }
  487.           }
  488.        }
  489.       else
  490.        {
  491.          if (   s[0] == '-'
  492.              || s[0] == '+')
  493.           {
  494.             switch (toupper(s[1]))
  495.              {
  496.                case 'D':
  497.                  mode = check_dvi;
  498.                  break;
  499.                case 'L':
  500.                  mode = check_log;
  501.                  break;
  502.                case 'M':
  503.                  with_message = !(s[2] == '-');
  504.                  break;
  505.                case 'S':
  506.                  if (   s[2] >= '1'
  507.                      && s[2] <= (Char)(columns_max + '0'))
  508.                    column_quantity = s[2] - '0';
  509.                  else
  510.                    column_quantity = 1;
  511.                  break;
  512.                default:
  513.                  error_stop (255);
  514.              }
  515.           }
  516.          else
  517.           {
  518.             strcpy(fn,s);
  519.             x = strpos2 (fn,".",1);
  520.             if (   !x
  521.                 || x == strlen(fn))
  522.              {
  523.                if (x == strlen(fn))
  524.                strdelete ((void *)fn,strlen(fn),1);
  525.                if (mode == check_dvi)
  526.                 {
  527.                   if (i + 1 <= parameter_quantity)
  528.                    {
  529.                      FORLIM1 = parameter_quantity;
  530.                      for (j=i+1 ; j <= FORLIM1 ; j++)
  531.                       {
  532.                         strcpy(s,my_argv[j]);
  533.                         if (strlen(s) >= 2)
  534.                          {
  535.                            if (   s[0] == '+'
  536.                                || s[0] == '-')
  537.                              s[1] = toupper(s[1]);
  538.                            if (strpos2 (s,"L",1))
  539.                              mode = check_log;
  540.                          }
  541.                       }
  542.                    }
  543.                 }
  544.                if (mode == check_dvi)
  545.                  strcat(fn,suffix_dvi);
  546.                else
  547.                  strcat(fn,suffix_log);
  548.              }
  549.             else
  550.              {
  551.                if (!strcmp(strsub (STR1,fn,strlen(fn)-3,strlen(fn)),suffix_dvi))
  552.                  mode = check_dvi;
  553.                else
  554.                 {
  555.                   if (!strcmp(strsub (STR2,fn,strlen(fn)-3,strlen(fn)),suffix_log))
  556.                     mode = check_log;
  557.                   else
  558.                    {
  559.                      if (mode == check_dvi)
  560.                        sprintf(fn,"%.*s%s",x-1,strcpy(STR4,fn),suffix_dvi);
  561.                      else
  562.                        sprintf(fn,"%.*s%s",x-1,strcpy(STR3,fn),suffix_log);
  563.                    }
  564.                 }
  565.              }
  566.           }
  567.        }
  568.     }
  569.    if (*fn != '\0')
  570.     {
  571.       strcpy(t_NAME,fn);
  572.       if (t != NULL)
  573.         t = freopen(t_NAME,"r",t);
  574.       else
  575.         t = fopen(t_NAME,"r");
  576.       _SETIO(t != NULL,FileNotFound);
  577.       error = P_ioresult;
  578.     }
  579.    else
  580.      error = 254;
  581.    if (error)
  582.      error_stop (error);
  583.    if (*fn != '\0')
  584.     {
  585.       pages                 = 0;
  586.       textline_finished     = false;
  587.       buffer_finished       = false;
  588.       first_buffer          = true;
  589.       read_textline         = true;
  590.       delete_next_bracket   = false;
  591.       id_byte_one_found     = false;
  592.       id_byte_two_found     = false;
  593.       if (mode == check_dvi)
  594.        {
  595.          strcpy(f_NAME,fn);
  596.          if (f != NULL)
  597.            f = freopen(f_NAME,"r+b",f);
  598.          else
  599.            f = fopen(f_NAME,"r+b");
  600.         if (f == NULL)
  601.           _EscIO(FileNotFound);
  602.         do
  603.          {
  604.            error = fread(dvibuf,1,(blocksize+1)*sizeof(uchar),f);
  605.            P_ioresult = 0;
  606.            if (error)
  607.             {
  608.               i = 0;
  609.               if (error == (unsigned short)(blocksize + 1))
  610.                 error = blocksize;
  611.               buffer_finished = false;
  612.               if (first_buffer)
  613.                {
  614.                  first_buffer = false;
  615.                  while (   dvibuf[i] != id_byte_one
  616.                         && i < error)
  617.                    i++;
  618.                  if (!dvibuf[i + 5])
  619.                   {
  620.                     pagenumber_decimal (document_pages[pages],
  621.                                         dvibuf[i + 1],
  622.                                         dvibuf[i + 2],
  623.                                         dvibuf[i + 3],
  624.                                         dvibuf[i + 4]);
  625.                     pages++;
  626.                   }
  627.                  i += 5;
  628.                }
  629.               while (!buffer_finished)
  630.                {
  631.                  if (id_byte_one_found)
  632.                   {
  633.                     if (dvibuf[i] == id_byte_one)
  634.                      {
  635.                        if (!dvibuf[i + 5])
  636.                         {
  637.                           pagenumber_decimal (document_pages[pages],
  638.                                               dvibuf[i + 1],
  639.                                               dvibuf[i + 2],
  640.                                               dvibuf[i + 3],
  641.                                               dvibuf[i + 4]);
  642.                           pages++;
  643.                           id_byte_one_found = false;
  644.                         }
  645.                        i += 4;
  646.                      }
  647.                     else
  648.                       id_byte_one_found = false;
  649.                   }
  650.                  if (id_byte_two_found)
  651.                   {
  652.                     if (!dvibuf[i + 4])
  653.                      {
  654.                        pagenumber_decimal (document_pages[pages],
  655.                                            dvibuf[i],
  656.                                            dvibuf[i + 1],
  657.                                            dvibuf[i + 2],
  658.                                            dvibuf[i + 3]);
  659.                        pages++;
  660.                        id_byte_two_found = false;
  661.                      }
  662.                     i += 3;
  663.                   }
  664.                  else
  665.                    id_byte_two_found = false;
  666.                  if (dvibuf[i] == id_byte_two)
  667.                   {
  668.                     if (   i == blocksize - 1
  669.                         && dvibuf[blocksize] == id_byte_one)
  670.                       id_byte_two_found = true;
  671.                     else
  672.                      {
  673.                        if (i == blocksize)
  674.                          id_byte_one_found = true;
  675.                        else
  676.                         {
  677.                           if (   dvibuf[i] == id_byte_two
  678.                               && dvibuf[i + 1] == id_byte_one)
  679.                            {
  680.                              if (!dvibuf[i + 6])
  681.                               {
  682.                                 pagenumber_decimal (document_pages[pages],
  683.                                                     dvibuf[i + 2],
  684.                                                     dvibuf[i + 3],
  685.                                                     dvibuf[i + 4],
  686.                                                     dvibuf[i + 5]);
  687.                                 pages++;
  688.                               }
  689.                              i += 5;
  690.                            }
  691.                         }
  692.                      }
  693.                   }
  694.                  if (i >= error)
  695.                    buffer_finished = true;
  696.                  else
  697.                    i++;
  698.                }
  699.             }
  700.          } while (error);
  701.         if (f != NULL)
  702.           fclose(f);
  703.         f = NULL;
  704.         error = P_ioresult;
  705.         if (error)
  706.           error_stop (error);
  707.         strcpy(f_NAME,fn);
  708.        }
  709.       else
  710.        {
  711.          setvbuf(t,textbuf,_IOFBF,blocksize + 1);
  712.          strcpy(t_NAME,fn);
  713.          if (t != NULL)
  714.            t = freopen(t_NAME,"r",t);
  715.          else
  716.            t = fopen(t_NAME,"r");
  717.          _SETIO(t != NULL,FileNotFound);
  718.          error = P_ioresult;
  719.          if (error)
  720.            error_stop (error);
  721.          _SETIO(fgets(textline,256,t) != NULL,EndOfFile);
  722.          TEMP = strchr(textline,'\n');
  723.          if (TEMP != NULL)
  724.            *TEMP = 0;
  725.          error = P_ioresult;
  726.          if (error)
  727.            error_stop (error);
  728.          while (!P_eof(t))
  729.           {
  730.             if (read_textline)
  731.              {
  732.                _SETIO(fgets(textline,256,t) != NULL,EndOfFile);
  733.                TEMP = strchr(textline,'\n');
  734.                if (TEMP != NULL)
  735.                *TEMP = 0;
  736.                error = P_ioresult;
  737.                if (error)
  738.                  error_stop (error);
  739.              }
  740.             else
  741.               read_textline = true;
  742.             i = 1;
  743.             while (i)
  744.              {
  745.                sprintf(STR5,"%c%c",id_char_one,id_char_two);
  746.                i = strpos2 (textline,STR5,1);
  747.                if (i)
  748.                  strdelete ((void *)textline,i,2);
  749.              }
  750.             textline_finished = false;
  751.             sprintf(STR1,"%c",id_char_one);
  752.             i = strpos2 (textline,STR1,1);
  753.             id_byte_one_found = (i != 0);
  754.             sprintf(STR1,"%c",id_char_two);
  755.             x = strpos2 (textline,STR1,1);
  756.             id_byte_two_found = (x != 0);
  757.             if (   (   id_byte_one_found
  758.                     && (   (textline[i] > '9' || textline[i] < '0')
  759.                         && textline[i] != '-'))
  760.                 || (   i > 1
  761.                     && textline[i - 2] != ' '))
  762.              {
  763.                id_byte_one_found = false;
  764.                id_byte_two_found = false;
  765.                strdelete ((void *)textline,i,1);
  766.              }
  767.             if (id_byte_one_found)
  768.              {
  769.                if (   textline[i] != '\0'
  770.                    && !id_byte_two_found)
  771.                 {
  772.                   strsub (document_pages[pages],textline,i+1,strlen(textline));
  773.                   if (pagenumber_ok (document_pages[pages]))
  774.                     pages++;
  775.                   id_byte_one_found = false;
  776.                   textline_finished = true;
  777.                   delete_next_bracket = true;
  778.                }
  779.              }
  780.             while (   id_byte_one_found
  781.                    && !textline_finished)
  782.              {
  783.                sprintf(STR1,"%c",id_char_two);
  784.                x = strpos2 (textline,STR1,1);
  785.                id_byte_two_found = (x != 0);
  786.                if (   id_byte_two_found
  787.                    && delete_next_bracket)
  788.                 {
  789.                   strcpy(textline,strsub (STR1,textline,x+1,strlen(textline)));
  790.                   delete_next_bracket = false;
  791.                   sprintf(STR1,"%c",id_char_two);
  792.                   x = strpos2 (textline,STR1,1);
  793.                   id_byte_two_found = (x != 0);
  794.                   if (id_byte_one_found)
  795.                    {
  796.                      sprintf(STR1,"%c",id_char_one);
  797.                      i = strpos2 (textline,STR1,1);
  798.                    }
  799.                   else
  800.                     textline_finished = true;
  801.                 }
  802.                if (   id_byte_two_found
  803.                    && !textline_finished)
  804.                 {
  805.                   if (x <= i + 1)
  806.                     continue;
  807.                   strsub (document_pages[pages],textline,i+1,x-i-1);
  808.                   if (pagenumber_ok (document_pages[pages]))
  809.                     pages++;
  810.                   strcpy(textline,strsub (STR1,textline,x+1,strlen(textline)-x));
  811.                   sprintf(STR1,"%c",id_char_one);
  812.                   i = strpos2 (textline,STR1,1);
  813.                   id_byte_one_found = (i != 0);
  814.                   if (   *textline == '\0'
  815.                       && !id_byte_one_found)
  816.                     textline_finished = true;
  817.                   continue;
  818.                 }
  819.                if (!id_byte_one_found)
  820.                  break;
  821.                if (   textline[i] == '\0'
  822.                    || id_byte_two_found)
  823.                  continue;
  824.                strsub (document_pages[pages],textline,i+1,strlen(textline));
  825.                if (id_byte_two_found)
  826.                 {
  827.                   if (pagenumber_ok (document_pages[pages]))
  828.                     pages++;
  829.                   id_byte_one_found = false;
  830.                   textline_finished = true;
  831.                   delete_next_bracket = true;
  832.                   continue;
  833.                 }
  834.                while (   !id_byte_two_found
  835.                       && !P_eof(t))
  836.                 {
  837.                   fgets(textline,256,t);
  838.                   TEMP = strchr(textline,'\n');
  839.                   if (TEMP != NULL)
  840.                     *TEMP = 0;
  841.                   sprintf(STR1,"%c",id_char_two);
  842.                   x = strpos2 (textline,STR1,1);
  843.                   id_byte_two_found = (x != 0);
  844.                 }
  845.                if (!id_byte_two_found)
  846.                  continue;
  847.                sprintf(document_pages[pages]+strlen(document_pages[pages]),
  848.                        "%.*s",x-1,textline);
  849.                strcpy(textline,strsub (STR2,textline,x+1,strlen(textline)));
  850.                if (pagenumber_ok (document_pages[pages]))
  851.                  pages++;
  852.                id_byte_one_found = false;
  853.                textline_finished = true;
  854.                read_textline = false;
  855.              }
  856.             if (   delete_next_bracket
  857.                 && id_byte_two_found)
  858.               delete_next_bracket = false;
  859.           }
  860.          if (t != NULL)
  861.            fclose(t);
  862.          t = NULL;
  863.          error = P_ioresult;
  864.          if (error)
  865.            error_stop (error);
  866.        }
  867.       if (with_message)
  868.        {
  869.          if (pages > 0)
  870.           {
  871.             printf("%s",copyright);
  872.             printf("%s\n",underline);
  873. #ifdef GERMAN
  874.             printf("Dokumentdatei           = %s\n",fn);
  875.             printf("Seitenanzahl insgesamt  = %u\n\n",pages);
  876.             printf("Im Dokument vorhandene Seitennummern :\n");
  877.             printf("--------------------------------------\n");
  878. #else
  879.             printf("Document file       = %s\n",fn);
  880.             printf("Total page numbers  = %u\n\n",pages);
  881.             printf("Page numbers existing in document :\n");
  882.             printf("-----------------------------------\n");
  883. #endif
  884.           }
  885.        }
  886.       if (pages > 0)
  887.        {
  888.          i = 0;
  889.          x = 0;
  890.          while (i < pages)
  891.           {
  892.             if (column_quantity == 1)
  893.               fputs(document_pages[i],stdout);
  894.             else
  895.               printf("%*s",column_width,document_pages[i]);
  896.             i++;
  897.             x++;
  898.             if (x == column_quantity)
  899.              {
  900.                putchar('\n');
  901.                x = 0;
  902.              }
  903.           }
  904.        }
  905.       else
  906.         error_stop (252);
  907.     }
  908.    if (x)
  909.      putchar('\n');
  910.    if (f != NULL)
  911.      fclose(f);
  912.    if (t != NULL)
  913.      fclose(t);
  914.  
  915.    return(0);
  916.  }
  917.